﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PHMEE.Admin.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PHMEE.Admin.HttpApi.Controllers.MqttInfo
{
    /// <summary>
    /// 德通主动发送Topic
    /// </summary>
    [Route("phmeeadmin/api/[controller]/[action]")]
    public class DtSendTopicController : PHMEEAdminController
    {
        private IDtSendTopicService _dtSendTopicService;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dtSendTopicService"></param>
        public DtSendTopicController(IDtSendTopicService dtSendTopicService)
        {
            _dtSendTopicService = dtSendTopicService;
        }
        /// <summary>
        /// 通知重启数采器
        /// </summary>
        /// <returns></returns>\
        [HttpGet]
        public async Task<IActionResult> IssueRestart(string collectorCode)
        {
            bool status = await _dtSendTopicService.SendIssueRestartAsync(collectorCode);
            if (status)
                return Ok(new { Message = "Success" });
            else
                return Ok(new { Message = "Fail" });
        }
        /// <summary>
        /// 主动下发参数
        /// </summary>
        /// <param name="CollectorCode">数采器编码</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SysPara(string collectorCode)
        {
            bool status = await _dtSendTopicService.SendIssueParaAsync(collectorCode);
            if (status)
                return Ok(new { Message = "Success" });
            else
                return Ok(new { Message = "Fail" });
        }
        /// <summary>
        /// 手动触发采集站的自检，并返回没有下发成功的
        /// </summary>
        /// <param name="collectCodes"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<string>> GheckData(List<string> collectCodes)
        {
            return await _dtSendTopicService.CheckDataAsync(collectCodes);
        }
    }
}
